<?php
include_once dirname(__FILE__).'/../_include/session_start.php';
$config_dir = $_SESSION['config_dir'];
include "$config_dir/config.php";

// Set default values

// $logDir needed by _pages/conact/
//    proc_match_move.tpl.php
//    upload_contacts.tpl.php
//    proc_fetch_opt_in.tpl.php
if (!isset($logDir)) $logDir = $myName;

if (!isset($passwordDir)) $passwordDir = "/var/www/passwd/$myName";

// Set user role if not yet defined
if (!isset($_SESSION['role']))
{
  $user = $_SESSION['user'];
  //trigger_error("\$passwordDir '$passwordDir'");
  //trigger_error("\$user '$user'");
  
  //Evaluate user role based group file "$passwordDir/groups"
  $role = 'OPR';  //initialized to 'OPR', and upgraded to 'ADMIN'
  $gfile = fopen("$passwordDir/groups", 'r');
  if ($gfile)
  {
    while ($line = fgets($gfile))
    {
      $items = explode(' ', trim($line));
      if (in_array($user, $items))
      {
        // This line in the groups file contains $user
        if ($items[0] == 'admin:') $role = 'ADMIN';
      }
    }
  }
  //trigger_error("\$role '$role'");
  $_SESSION['role'] = $role;
}
?>
